package com.shanzmoo.h5.web;

import com.shanzmoo.h5.domain.bo.MemberTokenBO;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.h5.domain.bo.WxAuthAccessTokenBO;
import com.shanzmoo.h5.service.ILoginService;
import com.shanzmoo.h5.service.IWechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员登陆、注册管理
 * @author: Gzhao 2020/12/20
 */
@Api(tags = "会员服务-登陆（注册）管理")
@RestController
@RequestMapping("sso")
public class LoginController {

    @Value("${jwt.tokenHead}")
    private String tokenHead;

    @Autowired
    private ILoginService loginService;
    @Autowired
    private IWechatService wechatService;

    @ApiOperation("获取微信网页授权accessToken")
    @GetMapping("get/auth/wxAccessToken")
    public SHttpResponse<WxAuthAccessTokenBO> getWxAuthAccessToken(@RequestParam String code) {
        SResponse<WxAuthAccessTokenBO> accessTokenBO = wechatService.getWxAuthAccessToken(code);
        return SHttpResponse.transform(accessTokenBO);
    }

    @ApiOperation("短信注册登录发送验证码")
    @GetMapping("identifyingCode")
    public SHttpResponse<Boolean> sendIdentifyingCode(@RequestParam String phone) {
        SResponse<Boolean> accessTokenBO = loginService.sendIdentifyingCode(phone);
        return SHttpResponse.transform(accessTokenBO);
    }

    @ApiOperation("手机号登陆")
    @GetMapping("loginByPhone")
    public SHttpResponse<MemberTokenBO> loginByPhone(@RequestParam String phone, @RequestParam String code) {
        SResponse<MemberTokenBO> accessTokenBO = loginService.loginByPhone(phone, code);
        return SHttpResponse.transform(accessTokenBO);
    }

}
